require(['./config'],() => {
    require(['request','template','header','footer'],(request,template) => {
       class List {
           constructor () {
               
                this.load().then(() => {
                    this.init()
                    this.initSelect()
                    this.freshWindow()
                    this.start = 0
                })
           }
           load () {
            return new Promise(resolve => {
                $('header').load('/html/modules/header.html',resolve)
            })
            }
           init (start) {
            const id = window.location.hash.slice(1)
            request.getCategory(id,start).then(resp => {
                if (resp.code === 200) {
                    const {list} = resp.data.items
                    
                    var content = $('#product').html()
                    $('#product').html(content + template('proTemplate',{list})) 
                }
            })
           }
           initSelect () {
                request.getSelect().then(resp => {
                    if (resp.code === 200) {
                        const list = resp.body.product
                       
                        // $('#select').html("wwe")
                        // template('selectTemplate',{product})
                        $('#select').html(template('selectTemplate',{list})) 
                    }  
                }) 
           }

           freshWindow () {
                $(window).scroll( () => {  
                    if (($(window).scrollTop()) === ($(document).height() - $(window).height())) {
                //     //当滚动的高度〉=文档的高度-窗体的高度时；
                //     //我们需要去异步加载数据了
                    this.start = this.start + 20
                   
                    this.init(this.start)
                    }
                });
           
           }
       }
       new List()
    })
})


